from app import db
from app.models.company import Company  # 导入Company模型

class MainTable(db.Model):
    __tablename__ = 'mainTable'
    
    id = db.Column(db.Integer, primary_key=True)
    mid = db.Column(db.String(20), nullable=False)
    cid = db.Column(db.String(20), nullable=False)  # 添加外键
    pid = db.Column(db.String(20), nullable=False)
    league = db.Column(db.String(50), nullable=False)
    parties = db.Column(db.String(100), nullable=False)
    first_half = db.Column(db.String(20), nullable=True)
    end_half = db.Column(db.String(20), nullable=True)
    goal_time = db.Column(db.String(50), nullable=True)
    morning_seesion = db.Column(db.String(50), nullable=True)
    closing_session = db.Column(db.String(50), nullable=True)
    midfield = db.Column(db.String(50), nullable=True)
    big_small_plate = db.Column(db.String(20), nullable=True)
    mid_big_small_plate = db.Column(db.String(20), nullable=True)
    result = db.Column(db.String(20), nullable=True)
    t = db.Column(db.String(20), nullable=False,default="1")
    midtime = db.Column(db.String(20), nullable=False)
    
    def to_dict(self):
        """转换为字典，方便接口返回"""
        return {
        'id': self.id,
        'mid': self.mid,
        'cid': self.cid,
        'pid': self.pid,
        'league': self.league,
        'parties': self.parties,
        'first_half': self.first_half,
        'end_half': self.end_half,
        'goal_time': self.goal_time,
        'morning_seesion': self.morning_seesion,
        'closing_session': self.closing_session,
        'midfield': self.midfield,
        'big_small_plate': self.big_small_plate,
        'mid_big_small_plate': self.mid_big_small_plate,
        'result': self.result,
        'midtime': self.midtime,
        't':self.t
    }